/**
 * <p>Title: ServiceZMCMH0.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 贾雪民
 * @version 1.0
 * <pre>Histroy:
 *          2011-5-31 下午02:30:43  贾雪民  Create
 *</pre>
 */
package com.baosight.sczx.zm.cm.service;

import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.OrgEmp;
import com.baosight.sczx.zm.cm.domain.ZMCMMaterialType;
import com.baosight.sczx.zm.cm.domain.ZMCMTypeManageMentSet;

/**库房分管设置
 * <p>Title: ServiceZMCMH0.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 贾雪民
 * @version 1.0
 * <pre>Histroy:
 *          2011-5-31 下午02:30:43  贾雪民  Create
 *</pre>
 */
public class ServiceZMCMH0 extends ServiceEPBase{

	/**初始数据
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCMH0</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-5-31下午02:35:57 贾雪民
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的		
		EiInfo outInfo = this.query(inInfo);		
		outInfo.addBlock(this.getEmpName());
		//outInfo.addBlock(this.getMateroalName());		
		return outInfo;
	}
	
	/**列表查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCMH0</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-5-31下午02:35:57 贾雪民
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		
		String fdMaterialId = inInfo.getString("fdMaterialId");
		StaticTools.setQueryParameters(inInfo, fdMaterialId, fdMaterialId, true);//添加查询条件		
		EiInfo outInfo = super.query(inInfo, "ZMCMTypeManageMentSet.query",new ZMCMTypeManageMentSet());
		return outInfo;
	}
	
	/**物资分类查询
	 * <p>Function: type</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCMH0</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-7下午05:35:57 贾雪民
	 * </p>
	 *
	 */
	public EiInfo type(EiInfo info) {
		ZMCMMaterialType type = new ZMCMMaterialType();
		return super.query(info, "ZMCMMaterialType.querytype", type);
	}
	/**新增
	 * <p>Function: insert</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCMH0</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-5-31下午02:35:57 贾雪民
	 * </p>
	 *
	 */
	@Override
	public EiInfo insert(EiInfo inInfo) {
		//校验物资分类是否重复
		//boolean validate = validate(inInfo, "ZMCMTypeManageMentSet.validate", new HashMap<String, String>());
		boolean validate = false;
		if(validate) {
			return inInfo;
		}
		else {
			inInfo.getBlock("result").setCell(0, "fdKeyId", TablePk.getInstance().getNextValue("T_CM_TypeManageMentSet"));//主键
			EiInfo outInfo = super.insert(inInfo, "ZMCMTypeManageMentSet.insert");
			return outInfo;
		}
	}
	
	/**修改
	 * <p>Function: update</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCMH0</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-5-31下午02:35:57 贾雪民
	 * </p>
	 *
	 */
	@Override
	public EiInfo update(EiInfo inInfo) {
		EiInfo outInfo = super.update(inInfo, "ZMCMTypeManageMentSet.update");
		return outInfo;
	}
	
	/**删除
	 * <p>Function: delete</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCMH0</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-5-31下午02:35:57 贾雪民
	 * </p>
	 *
	 */
	@Override
	public EiInfo delete(EiInfo inInfo) {
		EiInfo _temp = super.delete(inInfo,"ZMCMTypeManageMentSet.delete","result");
		EiInfo outInfo = this.query(inInfo);		
		outInfo.setMsg(_temp.getMsg());
		outInfo.setDetailMsg(_temp.getDetailMsg());
		return outInfo;
	}

	/**
	 * 构造物资分类block
	 * <p>Function: getMateroalName</p>
	 * <p>Description: </p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-7下午02:48:28 贾雪民
	 * </p>
	 *
	 */
//	@SuppressWarnings("rawtypes")
//	private EiBlock getMateroalName(){
//	    EiBlock block = new EiBlock("cmes.cm.materoalName");
//			
//	    EiColumn eiColumn = new EiColumn("materoalId");
//		eiColumn.setType("C");
//		block.addMeta(eiColumn);
//		
//		eiColumn = new EiColumn("materoalName");
//		eiColumn.setType("C");
//		block.addMeta(eiColumn);
//		Map<String, String> _map = new HashMap<String, String>();
//		List<Map> list = Material.getMateroalNames(_map,"ZMCMMaterialType.type1");
//		
//		block.setRows(list);
//		return block;	
//	}
	
	/**
	 * 构造人员block
	 * <p>Function: getEmpName</p>
	 * <p>Description: </p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-7下午02:48:28 贾雪民
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	private EiBlock getEmpName(){
	    EiBlock block = new EiBlock("cmes.cm.empName");
			
	    EiColumn eiColumn = new EiColumn("empCode");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("empName");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map> list = OrgEmp.getEmpNames();
		
		block.setRows(list);
		return block;	
	}
	
	/**
	 *
	 * 校验重复
	 * <p>Function: validate</p>
	 * <p>Description: </p>
	 * <p>return value:boolean</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-1下午02:35:57 贾雪民
	 * </p>
	 *
	 */	
//	private boolean validate(EiInfo inInfo, String sqlName, Map<String, String> params) {
//		if(params == null) {
//			params = new HashMap<String, String>();
//		}
//		params.put("fdMaterialId", inInfo.getBlock("result").getCellStr(0, "fdMaterialId"));
//
//		List result = dao.query(sqlName, params);
//		if(result!=null && result.size() > 0) {
//			inInfo.setStatus(-1);
//			inInfo.setMsg("物资分类必须唯一！");
//			return true;
//		}
//		return false;
//	}
}
